package com.njmaomao.gj.pyot.config;

import com.njmaomao.gj.pyot.common.bean.BaseRequest;
import org.slf4j.MDC;
import org.springframework.core.NamedThreadLocal;

public abstract class RequestContext {

    private static final ThreadLocal<BaseRequest> currentBaseRequest = new NamedThreadLocal<>("Current Request");

    private static BaseRequest currentRequest() {
        BaseRequest baseRequest = currentBaseRequest.get();
        return baseRequest;
    }

    public static String currentSeqNo() {
        if(null == currentRequest()){
            return MDC.get("seqNo");
        }
        return currentRequest().getSeqNo();
    }

    public static void setCurrentRequest(BaseRequest request) {
        currentBaseRequest.set(request);
    }

    public static void removeCurrentRequest() {
        currentBaseRequest.remove();
    }

}